package org.zjh.controller.listener;

import org.zjh.utils.FrameAndPanelUtil;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @description: 窗口关闭 不退出程序
 * @author 郑佳豪
 * @date 2024/10/2 14:44
 * @version 1.0
 */
public class FrameCloseLis extends WindowAdapter {
    private static final FrameCloseLis frameCloseLis = new FrameCloseLis();


    @Override
    public void windowClosing(WindowEvent e) {

        int choice = JOptionPane.showConfirmDialog(null, "是否关闭", "温馨提示", JOptionPane.YES_NO_OPTION);
        if (choice == 0){
            //通过窗口关闭 页面的文本框刷新
            FrameAndPanelUtil.panelRefresh();
            //页面窗口设为不可见
            FrameAndPanelUtil.FrameSetVisibleFalse();
        }
    }

    public static FrameCloseLis getInstance() {
        return frameCloseLis;
    }
}
